#!/bin/bash -e

PACKAGE_DIR=/var/vcap/packages/postgres-15

STORE_DIR=/var/vcap/store

# then we switched to including version so it is easier to detect version changes
DATA_DIR=$STORE_DIR/postgres-15

JOB_DIR=/var/vcap/jobs/postgres
RUN_DIR=/var/vcap/sys/run/bpm/postgres

HOST=<%= p("postgres.listen_address") %>
PORT=<%= p("postgres.port") %>
USER='<%= p("postgres.user") %>'

export LD_LIBRARY_PATH="$PACKAGE_DIR/lib:$LD_LIBRARY_PATH"


cp $JOB_DIR/config/postgresql.conf $DATA_DIR

/var/vcap/jobs/postgres/bin/create-database &

echo "Starting PostgreSQL:"
exec $PACKAGE_DIR/bin/postgres -h $HOST -p $PORT -D $DATA_DIR
